package com.yu.util;

import java.util.List;

public class Page<T> {
    private Long pageNum;
    private Long pageCount;
    private Long totalPage;
    private Long totalCount;
    private Long rowNum;
    private List<T> list;


    public Long getPageNum() {
        return pageNum;
    }

    public void setPageNum(Long pageNum) {

        if(pageNum==null||pageNum<=1){
            this.pageNum=1L;
            return;
        }
        this.pageNum = pageNum;
    }

    public Long getPageCount() {
        return pageCount;
    }

    public void setPageCount(Long pageCount) {

        if(pageCount==null||pageCount<=0L){
            this.pageCount = 10L;
            return;
        }
        this.pageCount = pageCount;
    }

    public Long getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Long totalPage) {
        this.totalPage = totalCount%pageCount==0?totalCount/pageCount:totalCount/pageCount+1;
    }

    public Long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Long totalCount) {

        if(totalCount==null||totalCount<=0){
            this.totalCount = 0L;
            return;
        }
        this.totalCount = totalCount;
    }

    public Long getRowNum() {
        return rowNum;
    }

    public void setRowNum(Long rowNum) {
        this.rowNum = pageCount*(pageNum-1);
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageNum=" + pageNum +
                ", pageCount=" + pageCount +
                ", totalPage=" + totalPage +
                ", totalCount=" + totalCount +
                ", rowNum=" + rowNum +
                ", list=" + list +
                '}';
    }

    public void init(Long pageNum,Long pageCount,Long totalCount){
        setTotalCount(totalCount);
        setPageCount(pageCount);
        setTotalPage(0L);
        setPageNum(pageNum);
        setRowNum(0L);
    }
}
